﻿using Factory.ProductionManagement.Procedure;
using Factory.ProductionManagement.ProcedureSettings;
using Factory.ProductionManagement.ProcedureSettings.Dto;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
using ZXing.QrCode.Internal;

namespace Factory.Web.Controllers.ProductionManagement.ProcedureSettings
{
    public class ProcedureSettingController : Controller
    {
        /// <summary>
        /// 操作步骤服务接口
        /// </summary>
        private readonly IProcedureAppService _procedureAppService;
        /// <summary>
        /// 工序设置服务接口
        /// </summary>
        private readonly IProcedureSettingAppService _procedureSettingAppService;
        public ProcedureSettingController(IProcedureAppService procedureAppService, IProcedureSettingAppService procedureSettingAppService)
        {
            _procedureAppService = procedureAppService;
            _procedureSettingAppService = procedureSettingAppService;
        }
        /// <summary>
        /// 打开视图
        /// </summary>
        /// <returns>转到视图</returns>
        public IActionResult ProcedureSetting()
        {
            return View();
        }
        /// <summary>
        /// 添加工序设置
        /// </summary>
        /// <param name="procedureSettingDto">工序设置的数据</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public async Task<int> Insert(ProcedureSettingDto procedureSettingDto)
        {
            var reslut = await _procedureSettingAppService.Insert(procedureSettingDto);
            return reslut;
        }
        /// <summary>
        /// 工序设置信息分页显示
        /// </summary>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">页容量</param>
        /// <param name="inquireCode">工序设置编码</param>
        /// <returns>返回结果</returns>
        [HttpGet]
        public async Task<JsonResult> PageList(int pageIndex, int pageSize, string? inquireCode)
        {
            var list = await _procedureSettingAppService.PageList(pageIndex, pageSize, inquireCode);
            return Json(list);
        }
        /// <summary>
        /// 删除工序设置信息
        /// </summary>
        /// <param name="id">工序设置主键</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public async Task<int> Deleted(string id)
        {
            var reslut = await _procedureSettingAppService.Deleted(id);
            return reslut;
        }
        /// <summary>
        /// 编辑重复性验证
        /// </summary>
        /// <param name="code">供应商编码</param>
        /// <param name="id">供应商主键</param>
        /// <returns>返回结果</returns>
        [HttpGet]
        public async Task<int> UpdateRepeatability(string code, int id)
        {
            var reslut = await _procedureSettingAppService.UpdateRepeatability(code, id);
            return reslut;
        }
        /// <summary>
        /// 编辑工序设置信息
        /// </summary>
        /// <param name="procedureSettingDto">编辑的供应商信息</param>
        /// <returns>返回结果</returns>
        [HttpPost]
        public async Task<int> Update(ProcedureSettingDto procedureSettingDto)
        {
            var reslut = await _procedureSettingAppService.Update(procedureSettingDto);
            return reslut;
        }
    }
}
